using System;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using JMClient.ViewModels;
using Prism.Dialogs;
using Prism.Navigation.Regions;

namespace JMClient.Views;

public partial class SandboxWindow : UserControl,IDialogWindow
{
    public void Close()
    {
         
    }

    public void Show()
    {
         
    }

    public Task ShowDialog(Window owner)
    {
        return null;
    }

    public WindowBase Owner { get; }
    public IDialogResult Result { get; set; }
    public event EventHandler? Opened;
    public event EventHandler? Closed;
    public event EventHandler<WindowClosingEventArgs>? Closing;

    public SandboxWindow(IRegionManager regionManager)
    {
        InitializeComponent();
        
        // 将 RegionManager 绑定到当前窗口
        _regionManager = regionManager;
        // 如果你在窗口中定义了 Region（例如 ContentControl），这一步很关键

        
        this.Loaded  += LoadRegion;
    }
    private readonly IRegionManager _regionManager;
    private void LoadRegion(object? sender,RoutedEventArgs routedEventArgs)
    {
         
        if (DataContext is IDialogAware vm &&
            vm is SandboxWindowViewModel dialogVm)
        {
            RegionManager.SetRegionManager(this, dialogVm.ScopedRegionManager);
            RegionManager.UpdateRegions();
            dialogVm.LoadRegion();
        }
        
         
    }
}